<?php
class InvoiceAddress extends AppModel {

	public $name = 'InvoiceAddress';
	public $useTable = 'addresses';

        public $validate = array(
            'type' => array(
                'list' => array(
                    'rule' => array('equalTo', 'invoice')
                ),
            ),

            'country' => array(
                'required' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank'
                ),
            ),

            'zipcode' => array(
                'required' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank'
                ),
                'min' => array(
                    'rule' => array('minLength', 3),
                    'message' => 'zip code must be at least 3 characters long.'
                ),
            ),

            'city' => array(
                'required' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank'
                ),
            ),

            'location' => array(
                 'required' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank'
                ),
            )
        );

	public function beforeFind($queryData){
	    $queryData["conditions"]["type"]="invoice";
	    return $queryData;
	}
        
	public function beforeSave(){
	    $this->data["InvoiceAddress"]["type"]="invoice";
	    return true;
	}

	public function toLine($address){
	    return $address["InvoiceAddress"]["country"]." ".
	           $address["InvoiceAddress"]["zipcode"]." ".
	           $address["InvoiceAddress"]["city"]." ".
	           $address["InvoiceAddress"]["location"];
	}
	

}

?>